package com.fanjia.taobao.log.controller;

import com.fanjia.taobao.common.util.ResEntity;
import com.fanjia.taobao.common.util.ResponseUtil;
import com.fanjia.taobao.log.aop.Log;
import com.fanjia.taobao.log.entity.MyLog;
import com.fanjia.taobao.log.service.MyLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 日志表(MyLog)表控制层
 *
 * @author fanjia
 * @since 2021-04-23 08:31:17
 */
@RestController
@RequestMapping("/logManage")
public class MyLogController {
    @Autowired
    private MyLogService myLogService;

    //查询日志
    @GetMapping("/log")
    public ResEntity query(MyLog myLog,@RequestParam(defaultValue = "1") int pageNum,@RequestParam(defaultValue = "10") int pageSize){

        List<MyLog> myLogList = myLogService.query(myLog,pageNum,pageSize);
        int count = myLogService.queryCount(myLog);

        Map<String,Object> map = new HashMap<>();
        map.put("myLogList",myLogList);
        map.put("count",count);
        return ResponseUtil.success(map);
    }

    //删除日志
    @DeleteMapping("/log/{id}")
    public ResEntity delete(@PathVariable("id") int id){
        myLogService.delete(id);
        return ResponseUtil.success("删除成功");
    }



}